package com.feib.stms.dao;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.feib.stms.model.UploadFile;
import com.feib.stms.model.User;
import com.feib.stms.pagination.PaginatedList;
import com.feib.stms.service.UploadFileService;


@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"applicationContext-config.xml", "applicationContext-dao.xml"})
public class UploadFileDaoTester {

	
	@Autowired
	@Qualifier("uploadFileService")
	private UploadFileService uploadFileService;
	
	
	
	public  static UploadFileDao uploadFileDao;
	
	

		@Test
		public void testQueryByPaginatedList()
		{
		
			PaginatedList<UploadFile> paginatedList = new PaginatedList<UploadFile>();
			
			paginatedList.setPageSize(10);
			paginatedList.setPageNumber(2);
			paginatedList.setSortCriterion("upload_Date");
			paginatedList.setSortDirection(1);
			  Date qryUploaddDateFrom = new Date();
		      Date qryUploadDateTo = new Date();
		       Integer qryUploadDateHourFrom = new Integer(0);
		       Integer qryUploadDateHourTo = new Integer(24);
		       
		       
		       
		        Calendar cal = Calendar.getInstance();
		        cal.setTime(qryUploaddDateFrom);
		        cal.set(Calendar.HOUR_OF_DAY, qryUploadDateHourFrom);		     
		        cal.add(Calendar.YEAR, -2); // 目前時間減2年
		        //cal.set(2000,   7,   31,   0,   0   ,   0);
		        qryUploaddDateFrom = cal.getTime();
		        System.out.print("qryUploaddDateFrom: " +qryUploaddDateFrom);

		        /* 設定查詢條件-上傳日期迄*/
		        cal.setTime(qryUploadDateTo);
		        cal.set(Calendar.HOUR_OF_DAY, qryUploadDateHourTo);
		        qryUploadDateTo = cal.getTime();
		        
		        UploadFile o1 = new UploadFile();
		        o1.setUploadFilePk(new Long(1));
		        //o1.setFileName("TEST1");
		        o1.setUploadDate(new Date());
		        o1.setUploadUser(new User());
		        //o1.getUploadUser().setUserId("jimmyliu");//測試不輸入上傳人
		        o1.getUploadUser().setDealSecuritiesNos("2543,2444");
		        
		        List<String> fileFormats = new ArrayList<String>();
		        fileFormats.add("1");
		        fileFormats.add("2");
		        paginatedList=uploadFileService.findPaginatedListByUploadFile(o1, qryUploaddDateFrom, qryUploadDateTo, null, null, fileFormats, paginatedList);
		
		   //    for(int i=0;i<paginatedList.getFullListSize();i++){
		    	
		    	System.out.print(paginatedList);

		   //    }
		
		}
		

	

}
